

set(SRC_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(PARSER_DIR "${CMAKE_CURRENT_LIST_DIR}/gen")

set(LEXER_MID "${PARSER_DIR}/lexer.m")
set(LEXER_OUT "${PARSER_DIR}/lexer.c")
set(PARSER_OUT "${PARSER_DIR}/parser.c")

#set(NO_YACC_PROCESS 1)
if (NOT NO_YACC_PROCESS)
    find_package(FLEX 2.6 REQUIRED)
    find_package(BISON 3.0 REQUIRED)
    flex_target(LEXER "${SRC_DIR}/yylex.l" "${LEXER_MID}"
            COMPILE_FLAGS "--noline" #lex文件带行号注释会影响调试器
            DEFINES_FILE "${PARSER_DIR}/lexer.h")
    bison_target(PARSER "${SRC_DIR}/yyparser.y" "${PARSER_OUT}"
            # COMPILE_FLAGS "-l" #yacc文件的行号没影响
            DEFINES_FILE "${PARSER_DIR}/parser.h")
    add_flex_bison_dependency(LEXER PARSER)

    #即使有--noline参数，flex文件头部仍然会有一个行号注释，把它去掉
    add_custom_command(OUTPUT ${LEXER_OUT}
            COMMAND sed "1d" ${LEXER_MID} > ${LEXER_OUT}
            VERBATIM
            DEPENDS ${LEXER_MID}
    )
endif ()

file(GLOB SRCLIST *.cpp)
message(${SRCLIST})
add_library(css ${SRCLIST} ${LEXER_OUT} ${PARSER_OUT})
target_include_directories(css PUBLIC "${SRC_DIR}")
target_include_directories(css PRIVATE "${PARSER_DIR}")

#target_link_libraries(css folly)
